package com.crois.barrier.admin.spring;

import org.springframework.context.ConfigurableApplicationContext;

/**
 * @author Hou Ze Yu
 * @description
 * @date 2020/10/23
 */
public final class SpringBeanUtils {

    private static final SpringBeanUtils instance = new SpringBeanUtils();

    private ConfigurableApplicationContext cfgContext;

    private SpringBeanUtils() {
        if (instance != null) {
            throw new Error("error");
        }
    }

    /***
     * 得到SpringBeanUtils
     * @return
     */
    public static SpringBeanUtils getInstance() {
        return instance;
    }

    /***
     * 得到bean
     * @param type
     * @param <T>
     * @return
     */
    public <T> T getBean(final Class<T> type) {
        return cfgContext.getBean(type);
    }

    /***
     * 设置context
     * @param cfgContext
     */
    void setCfgContext(final ConfigurableApplicationContext cfgContext) {
        this.cfgContext = cfgContext;
    }

    /***
     * 得到applicationContext
     * @return
     */
    public ConfigurableApplicationContext getApplicationContext(){
        return cfgContext;
    }
}
